<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../vue 2.6.10.js"></script>
</head>
<body>
    <div id="app">
        姓：<input type="text" v-model="firstName"><br><br>
        名：<input type="text" v-model="lastName"><br><br>
        <!-- 方式1：插值语法 -->
        全名：<span>{{firstName}}-{{lastName}}</span><br><br>

        <!-- 全名2：<span>{{fullName()}}</span> -->

        全名3:<span>{{fullName}}</span>
    </div>
    <script>
        Vue.config.productionTip = false;

        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    firstName: "张",
                    lastName: "三"
                }
            },
            // methods: {
            //     fullName(){
            //         return this.firstName + this.lastName
            //     }
            // },
            computed: {
                fullName:{
                    // 读取
                    get(){
                        // this指向 vm
                        console.log(this)
                        console.log("get调用");
                        return this.firstName +"-"+ this.lastName
                    },
                    // fullName发生修改时调用，一般不修改
                    set(value){
                        const arr = value.split("-")
                        console.log(arr);
                        this.firstName = arr[0]
                        this.lastName = arr[1]
                    }
                }

                // fullName() {
                //     return this.firstName + "-" + this.lastName
                // }
            }
        })
    </script>
</body>
</html>